#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2018-08-23 14:23:22
# @Author  : wanglele (18911756410@163.com)
# @Link    : None
# @Version : "Python 3.7"

import os
import sys
import pandas as pd
from pyecharts import Bar, Pie, Page, Scatter3D

page = Page()

text = pd.read_csv(
    "wechat.csv",
    sep=",",
    delimiter=None,
    header="infer",
    names=None,
    index_col=None,
    usecols=None,
    squeeze=False,
    prefix=None,
    mangle_dupe_cols=True,
    dtype=None,
    engine=None,
    converters=None,
    true_values=None,
    false_values=None,
    skipinitialspace=False,
    skiprows=None,
    nrows=None,
    na_values=None,
    keep_default_na=True,
    na_filter=True,
    verbose=False,
    skip_blank_lines=True,
    parse_dates=False,
    infer_datetime_format=False,
    keep_date_col=False,
    date_parser=None,
    dayfirst=False,
    iterator=False,
    chunksize=None,
    compression="infer",
    thousands=None,
    decimal=b".",
    lineterminator=None,
    quotechar='"',
    quoting=0,
    escapechar=None,
    comment=None,
    encoding="gb18030",
    dialect=None,
    tupleize_cols=None,
    error_bad_lines=True,
    warn_bad_lines=True,
    skipfooter=0,
    doublequote=True,
    delim_whitespace=False,
    low_memory=True,
    memory_map=False,
    float_precision=None,
)
t = pd.DataFrame(text)
Sex = t["Sex"].value_counts()
# Province = list(set([i for i in t['Province']]))
# Province_num = [i for i in t['Province'].value_counts()]
# print(Sex)
# print(t['Province'].value_counts())
# print(t["Signature"])


bar = Bar("我的朋友", "微信分布")
sex = ["男", "女", "未知"]
v = [i for i in Sex]
pie = Pie(
    "饼图-玫瑰图示例",  # 图标标题
    title_pos="left",  # 标题左中右位置
    title_top="top",  # 标题上中下位置
    title_color="red",  # 标题文本颜色
    title_text_size=25,  # 标题文本大小
    subtitle="微信男女",  # 副标题
    subtitle_color="blue",  # 副标题文本颜色
    subtitle_text_size=15,  # 副标题文本大小
    width=1024,  # 图标区域的宽度
    height=500,  # 图标区域的高度
    background_color="#999",  # 图标区域背景颜色
)
pie.add(
    "性别比",  # 数据名
    sex,  # 数据标签
    v,  # 数据值
    center=[25, 50],
    is_radius=True,
    radius=[30, 75],
    is_legend_show=False,
    is_label_show=True,  # 标签
    is_more_utils=True,  # 更多工具箱
)

page.add(pie)

bar = Bar('朋友地区分布',
          width=1024,  # 图标区域的宽度
          height=500,  # 图标区域的高度
          )
dd = dict()
q_pro = list(set(t['Province']))
for p in q_pro:
    dd[p] = list(t['Province']).count(p)


key = []
val = []
for k, v in dd.items():
    key.append(k)
    val.append(v)
bar.add('地区', key, val)
print(key, val)
page.add(bar)


from random import randint

data = [[randint(0, 100), randint(0, 100), randint(0, 100)] for _ in range(80)]
range_color = ['#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8',
               '#ffffbf', '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026']

scatter3D = Scatter3D('3D散点图示例', width=1024, height=600)
scatter3D.add('', data, is_visualmap=True, visual_range_color=range_color)
page.add(scatter3D)
print(data)
print(range_color)

page.render()
